<?php

namespace Admin\Model\DBO;

use Zend\Db\TableGateway\AbstractTableGateway;
use Admin\Entity\Policy;

class CiculationPolicyDBO extends AbstractTableGateway {

    private $sm;
    private $ciculationPolicyTable;

    public function __construct($serviceManager) {
        $this->sm = $serviceManager;
    }

    public function getCiculationPolicyTable() {
        if (!$this->ciculationPolicyTable) {
            $this->ciculationPolicyTable = $this->sm->get('Admin\Model\DAO\CiculationPolicyTable');
        }
        return $this->ciculationPolicyTable;
    }

    public function fetchAll() {
        $resultSet = $this->getCiculationPolicyTable()->fetchAll();
        $iteratorAdapter = new \Zend\Paginator\Adapter\Iterator($resultSet);
        $paginator = new \Zend\Paginator\Paginator($iteratorAdapter);
        return $paginator;
    }
    public function getCiculationPolicy($policyID) {
        return $this->getCiculationPolicyTable()->getCiculationPolicy($policyID);
    }
    public function updatePolicy(Policy $policy) {
        $policyID = $policy->policyID;
        $data = array(
            'policyName' => $policy->policyName,
            'amount' => $policy->amount,
        );
        $this->getCiculationPolicyTable()->updatePolicy($data, $policyID);
    }
}

?>
